using System.CodeDom.Compiler;
using System.IO;
using EnvDTE;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.WowAddonStudio.Lua.LanguageService.Tests.WowCommonTestLibrary.Mocks;
using NUnit.Framework;

namespace WowProjectPackage.Tests
{
    public class GeneralDTETestBase
    {
		/// <summary>
		/// Gets the DTE.
		/// </summary>
		/// <value>The DTE.</value>
        protected internal static DTE DTE
        {
            get { return SimpleTestServiceLocator.Get<DTE>(); }
        }

		/// <summary>
		/// Sets this instance.
		/// </summary>
        [TestFixtureSetUp]
        public virtual void Set()
        {
            SimpleTestServiceLocator.Register<DTE>(new MockDTE());
            SimpleTestServiceLocator.Register<Project>(new MockOAProject(SimpleTestServiceLocator.Get<DTE>()));
            SimpleTestServiceLocator.Register<ProjectItem>(new MockProjectItem(SimpleTestServiceLocator.Get<Project>(),
                                    SimpleTestServiceLocator.Get<DTE>(), string.Empty));

            SimpleTestServiceLocator.Register<CodeDomProvider>(
				new MockLuaCodeDomProvider(SimpleTestServiceLocator.Get<ProjectItem>()));

            SimpleTestServiceLocator.Register<SVsShell>(new MockShell());
            SimpleTestServiceLocator.Register<SVsUIShell>(new MockShell());
            SimpleTestServiceLocator.Register<IVsUIShell>(new MockShell());
            SimpleTestServiceLocator.Register<IVsShell>(new MockShell());
            SimpleTestServiceLocator.Register<IVsRunningDocumentTable>(new MockShell());
            SimpleTestServiceLocator.Register<SVsTrackProjectDocuments>(new MockShell());
            
        }

        #region SetUp

		/// <summary>
		/// Sets up.
		/// </summary>
        [SetUp]
        public virtual void SetUp()
        {
        }

        #endregion

        #region TearDown

		/// <summary>
		/// Tears down.
		/// </summary>
        [TearDown]
        public virtual void TearDown()
        {
        }

        #endregion

        #region Tests

        #endregion

		/// <summary>
		/// Initializes the mock objects.
		/// </summary>
		/// <param name="source">The source.</param>
        protected virtual void InitializeMockObjects(string source)
        {
            ((MockProjectItem) SimpleTestServiceLocator.Get<ProjectItem>()).Object = source;
        }

		/// <summary>
		/// Creates the mock property.
		/// </summary>
		/// <param name="parent">The parent.</param>
		/// <param name="key">The key.</param>
		/// <param name="value">The value.</param>
		/// <returns></returns>
		protected static MockProperty CreateMockProperty(Properties parent, string key, string value)
		{
			return new MockProperty(DTE, key, parent, value);
		}

		/// <summary>
		/// Gets the source.
		/// </summary>
		/// <param name="fileName">Name of the file.</param>
		/// <returns></returns>
		protected static string GetSource(string fileName)
		{
			string source;
			using (var stream = File.OpenRead(fileName))
			using (var streamReader = new StreamReader(stream))
				source = streamReader.ReadToEnd();
			return source;
		}
    }
}